/**
 * Created by bethinner on 5/16/16.
 */
import React, { Component } from 'react';

import { connect } from 'react-redux'
import Link from 'react-router/lib/Link'
import browserHistory from 'react-router/lib/browserHistory'

import CardSimpleDescription from '../components/CardSimpleDescription'


export default class ItemCard extends Component{
    constructor(props){
        super(props);

        this.itemClick = this.itemClick.bind(this);
    }


    componentWillMount(){
    }
    itemClick(cardData){
        switch (this.props.itemType){
            //case -2://用于活动  不显示数量
            //    var mask = $('#mask');
            //    var weuiActionsheet = $('#weui_actionsheet');
            //    weuiActionsheet.addClass('weui_actionsheet_toggle');
            //    mask.show()
            //        .focus()//加focus是为了触发一次页面的重排(reflow or layout thrashing),使mask的transition动画得以正常触发
            //        .addClass('weui_fade_toggle').one('click', function () {
            //            hideActionSheet(weuiActionsheet, mask);
            //        });
            //    $('#actionsheet_cancel').one('click', function () {
            //        hideActionSheet(weuiActionsheet, mask);
            //    });
            //    mask.unbind('transitionend').unbind('webkitTransitionEnd');
            //
            //    function hideActionSheet(weuiActionsheet, mask) {
            //        weuiActionsheet.removeClass('weui_actionsheet_toggle');
            //        mask.removeClass('weui_fade_toggle');
            //        mask.on('transitionend', function () {
            //            mask.hide();
            //        }).on('webkitTransitionEnd', function () {
            //            mask.hide();
            //        })
            //    }
            //    this.props.clickFunc(cardData);
            //    break;
            case -1://跳转到未购买的卡券详情
                $('#loadingToast').show();
                browserHistory.push({
                        pathname:'/cardDetail',
                        state:{
                            cardID:cardData.card_id,
                            cardName:cardData.card_name
                        }
                    }
                );
                break;
            case 0:// 跳转到继续支付页面 continuePay
                $('#loadingToast').show();
                browserHistory.push({
                    pathname:'/continuePay',
                    state:{
                        data:cardData
                    }
                });
                break;
            case 1:
            case 2:
            case 3:
                $('#loadingToast').show();
                browserHistory.push({
                    pathname:'/myCardDetail',
                    state:{
                        data:cardData,
                        itemType:this.props.itemType
                    }
                });
                break;
            default:
                break

        }
    }
    render(){
        return(
            <div onClick={this.itemClick.bind(this,this.props.itemCardData)}>
                <div className="antd-row" style={{marginBottom:"3px"} }>
                    <div style={{width:"66.66666667%",float:"left"}}>
                        <img src={this.props.itemCardData.pic_url} style={{height:"100",width:"100%",borderRadius:"6px"}}/>
                    </div>
                    <div style={{width:"33.33333%",float:"left",overflow:"hidden"}}>
                        <CardSimpleDescription cardData={this.props.itemCardData} itemType={this.props.itemType}/>
                    </div>
                    <div style={{clear:"both"}}></div>
                </div>
            </div>

        )
    }
}

ItemCard.defaultProps = {
    itemCardData:{
        pic_url: "",
        purchase_price: "",
        stock: ""
    },
    itemType:0
}

ItemCard.propTypes = {
    itemCardData:React.PropTypes.object,
    index:React.PropTypes.number,
    itemType:React.PropTypes.number
}


